From: Lukas Schwaighofer <lukas@schwaighofer.name>
Date: Thu, 20 Apr 2017 23:26:01 +0200
Subject: configure.in: preserve CFLAGS
Forwarded: https://lists.alioth.debian.org/pipermail/pkg-security-team/Week-of-Mon-20170417/001267.html

This patch fixes two problems with configure.in:
* The [ and ] characters, which are part of the perl command, get
  removed by m4/autoconf processing.  The patch replaces them by @<:@
  and @:>@ so the perl snippet ends up correctly in the configure script
* Do not remove `-g` if it was explicitly included in the CFLAGS given
  to configure (the user knows best).  Instead only remove `-g` from the
  default CFLAGS.
---
 configure.in | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

--- a/configure.in
+++ b/configure.in
@@ -4,6 +4,8 @@
 AM_INIT_AUTOMAKE([1.9 foreign])
 AM_CONFIG_HEADER(config.h)
 
+# remove -g from the default flags
+: ${CFLAGS="-O2"}
 AC_PROG_CC
 AM_PROG_CC_STDC
 AC_HEADER_STDC
@@ -27,15 +29,10 @@
 AC_ARG_ENABLE(debug, [  --enable-debug          turn on debugging], enable_debug=yes, enable_debug=no)
 if test "x$enable_debug" = "xyes"; then
          # remove -O flags from CFLAGS
-         CFLAGS=`perl -e '$ARGV[0]=~s/-O\d?//g;print $ARGV[0]' -- "$CFLAGS"`
+         CFLAGS=`perl -e '$ARGV@<:@0@:>@=~s/-O\d?//g;print $ARGV@<:@0@:>@' -- "$CFLAGS"`
          # add debug parameters
          CFLAGS="$CFLAGS -g -DDEBUG -DDOJDEBUG"
          AC_MSG_RESULT(yes)
-else
-         # remove -g flags from CFLAGS
-         CFLAGS=`perl -e '$ARGV[0]=~s/-g//g;print $ARGV[0]' -- "$CFLAGS"`
-         CFLAGS="$CFLAGS -O2"
-         AC_MSG_RESULT(no)
 fi
 
 # produce Makefiles
